package com.finalProject;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class house_loan_calculater extends AppCompatActivity {
    EditText price;
    EditText month;
    EditText area;
    EditText rate;
    TextView show;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_house_loan_calculater);
        price=findViewById(R.id.housePrice);
        month=findViewById(R.id.month);
        area=findViewById(R.id.area);
        rate=findViewById(R.id.rate);
        show=findViewById(R.id.show_loan_monthly);

       
    }
    public  void house_loan_monthly(View view) {
        String priceValue = String.valueOf(price.getText());
        String rateValue = String.valueOf(rate.getText());
        String areaValue = String.valueOf(area.getText());
        String monthValue = String.valueOf(month.getText());
        if (priceValue.length() != 0 && rateValue.length() != 0 && areaValue.length() != 0 && monthValue.length() != 0) {
            double price=Double.parseDouble(priceValue);
            double month=Double.parseDouble(monthValue);
            double area=Double.parseDouble(areaValue);
            double rate=Double.parseDouble(rateValue);
            double monthly_loan=price*area*(100.0-rate)/month;
            show.setText(String.valueOf(monthly_loan));
        }
        else{
            show.setText("输入不合规");
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.item_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent start;
        switch (item.getItemId()) {
            case R.id.action_1:
                start=new Intent(house_loan_calculater.this,MainActivity.class);
                this.startActivity(start);
                Log.i("", "收入排行榜:跳转完毕 ");
                this.finish();
                break;
            case R.id.action_2:
                Log.i("", "onOptionsItemSelected: 退出成功");
                System.exit(0);
                this.finish();
                break;

        }
        return super.onOptionsItemSelected(item);
    }


}